import request from "@/utils/request";
import getUserProfileName from "@/utils/getUserProfile";

// 获取子卡分页列表数据
export function getSonCardListApi(query) {
  return request({
    url: "/fleetCard/sub/page",
    method: "get",
    params: query,
  });
}

// 子卡审核
export function setSonCardStatusApi(params) {
  return request({
    url: `/fleetCard/sub/review/${params.id}/status/${params.status}`,
    method: "put",
  });
}

// 批量删除子卡
export function patchDeleteSonCardApi(ids) {
  return request({
    url: `/fleetCard/sub/${ids}`,
    method: "delete",
  });
}

// 修改子卡
export function updateSonCardInfoApi(params) {
  return request({
    url: `/fleetCard/sub/${params.id}`,
    method: "put",
    data: params.fleetCardSubForm,
  });
}

//分配子卡金额
export function allocationSonCardAmountApi(params) {
  return request({
    url: `/fleetCard/sub/allocationAmount/${params.allocationAmount}/id/${params.id}`,
    method: "put",
  });
}

//  回收子卡额度
export function recycleSonCardlLimitApi(id) {
  return request({
    url: `/fleetCard/sub/recovery/${id}`,
    method: "put",
  });
}

// 子卡消费记录
export async function getSonCardConsumeRecordListApi(consumerId) {
  // 判断是否的admin 账号，如果不是，传 isDelete = 0 到后端，如果是则不用传参
  const isDelete = await getUserProfileName();
  let queryPlass;
  if (isDelete) {
    queryPlass = consumerId;
  } else {
    queryPlass = { ...consumerId, isDeleted: 0 };
  }

  return request({
    url: `/station/order/list/`,
    method: "get",
    params: queryPlass,
  });
}

export async function getList(consumerId) {
  // 判断是否的admin 账号，如果不是，传 isDelete = 0 到后端，如果是则不用传参
  const isDelete = await getUserProfileName();
  let queryPlass;
  if (isDelete) {
    queryPlass = consumerId;
  } else {
    queryPlass = { ...consumerId, isDeleted: 0 };
  }
  return request({
    url: "/fleet/payOrder/list",
    params: queryPlass,
  });
}

// /fleetCard/sub/add   新增车队卡子卡
export function leetCardSubAdd(fleetCardForm) {
  return request({
    url: "/fleetCard/sub/add",
    method: "post",
    data: fleetCardForm,
  });
}
